import { instance } from '../request'

const request = instance

/**
 * 获取角色列表
 *
 * @param page  分页页码
 * @param size  分页大小
 * @param sortId  分类id
 * @return
 */
export const getRolesListApi = (
  page: number,
  size: number,
  role: {
    sortId?: string
    realName?: string
    isDefault?: 1 | 0
  }
): PromiseRes<QueryRoleListItf> =>
  request.post(`/roles/rolesList?page=${page}&size=${size}`, role)

/**
 * 创建角色或者修改角色信息
 *
 * @param role   角色信息
 * @return s
 */
export const setRoleApi = (role: {
  name: string
  realName: string
  description: string
  isDefault: 0 | 1
  sortId?: string
  id?: string
}): PromiseRes => request.post(`/roles/setRole`, role)

/**
 * 批量删除角色
 *
 * @param roleIdList 角色id列表
 * @return s
 */
export const deleteRolesApi = (roleIdList: string[]): PromiseRes =>
  request.post(`/roles/deleteRoles`, roleIdList)

/**
 * 批量更新角色状态
 *
 * @param roleIdList 角色id 列表
 * @param status     状态 0启用，1禁用
 * @return s
 */
export const updateRolesStatusApi = (
  roleIdList: string[],
  status: 0 | 1
): PromiseRes =>
  request.post(`/roles/updateRolesStatus?status=${status}`, roleIdList)
